//package com.boot2.core.test.dynamicDataSourc;
//
//import com.boot2.core.dao.datasource.DynamicDataSourceConfig;
//import com.boot2.core.utils.StringUtils;
//import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
//import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
//import org.springframework.orm.jpa.JpaTransactionManager;
//import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
//import org.springframework.transaction.PlatformTransactionManager;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//
//import javax.sql.DataSource;
//import java.util.Map;
//
///**
// * @author zhangweilin
// * @date 2019/4/26 23:01
// * @description: 数据源test2
// */
//@Configuration
//@EnableTransactionManagement
//@EnableJpaRepositories(
//        entityManagerFactoryRef = "entityManagerFactoryTest3",
//        transactionManagerRef = "transactionManagerTest3",
//        basePackages = {"com.yoju.dao.admin"}) //设置Repository所在位置
////开启的开关为配置此值,即启用了多数据源，才走此配置文件
//@ConditionalOnProperty("spring.datasource.customDefaultName")
//public class DatasourceTest3Config {
//
//    private static final String dataSourceName = "Test3";
//    private static final String dataSourceName0 = StringUtils.changFirstWord(dataSourceName, 1);
//
//    @Autowired
//    DynamicDataSourceConfig dynamicDataSourceConfig;
//
//    @Autowired
//    BeanNameAutoProxyCreator beanNameAutoProxyCreator;
//
//    @Autowired
//    private JpaProperties jpaProperties;
//
//
//    private Map getVendorProperties(DataSource dataSource) {
//        return jpaProperties.getHibernateProperties(dataSource);
//    }
//
//    @Bean(name = "entityManagerFactoryTest3")
//    public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) {
//        DataSource dataSource = dynamicDataSourceConfig.getDataSource(dataSourceName0);
//        return builder
//                .dataSource(dataSource)
//                .properties(getVendorProperties(dataSource))
//                .packages("com.yoju.model.admin") //设置实体类所在位置
//                .persistenceUnit(dataSourceName0 + "PersistenceUnit")
//                .build();
//    }
//
//    @Bean(name = "transactionManagerTest3")
//    public PlatformTransactionManager transactionManager(EntityManagerFactoryBuilder builder) {
//        System.out.println("beanNameAutoProxyCreator = " + beanNameAutoProxyCreator);
//        JpaTransactionManager jpaTransactionManager = new JpaTransactionManager(entityManagerFactory(builder).getObject());
////        txConfig2.addTransaction(dataSourceName, jpaTransactionManager);
////        TransactionInterceptor tsi = new TransactionInterceptor(jpaTransactionManager, transactionProperties);
//        return jpaTransactionManager;
//    }
//
//
////    @Bean(name = "txAdviceTest3")
////    public TransactionInterceptor createTransactionInterceptor(EntityManagerFactoryBuilder builder) throws Exception {
////        PlatformTransactionManager platformTransactionManager = transactionManager(builder);
////        System.out.println("platformTransactionManager = " + platformTransactionManager);
////        TransactionInterceptor tsi = txConfig2.createTransactionInterceptor(platformTransactionManager);
////        return tsi;
////    }
//
////    @Bean("BeanNameAutoProxyCreator3")
////    public BeanNameAutoProxyCreator txProxy() {
////        BeanNameAutoProxyCreator creator = new BeanNameAutoProxyCreator();
////        creator.setInterceptorNames("txAdviceTest3");
////        creator.setBeanNames("*Service", "*Dao");
////        creator.setProxyTargetClass(true);
////        this.beanNameAutoProxyCreator = creator;
////        return creator;
////    }
//}